#!/usr/bin/env python
# Create: 2018/11/6
__author__ = '749B'
"""读取文件的NodeName和IP，进行批量修改"""

import os.path


def get_info(file_name):
    if not os.path.exists(file_name):
        print("文件不存在", file_name)
        return
    with open(file_name, encoding='utf-8') as f:
        for line in f:
            if not line.strip():
                continue
            s = line.strip().split(maxsplit=1)
            if len(s) != 2:
                print("行内分隔异常:", s)
                continue
            name, ip = s
            yield name.strip(), ip.strip()


if __name__ == '__main__':
    from sds import update_node_name
    file_name = "node_test.txt"
    count = 0
    for node, ip in get_info(file_name):
        count += 1
        update_node_name.run(ip, node)

    print("\n处理总数:", count)

